export function toFormat(format, t) {
    t = new Date(t)
    if (!format) {
      let now = new Date()
      if (t.getFullYear() != now.getFullYear()) format = 'YYYY-MM-DD hh:mm'
      else if (t.getMonth() != now.getMonth() || t.getDate() != now.getDate()) format = 'MM-DD hh:mm'
      else format = 'hh:mm'
    }
    var Y = (t.getFullYear() + 1e4).toString().slice(1)
    return format
      .replace(/YYYY/gi, Y)
      .replace(/YY/g, Y.slice(2))
      .replace(/MM/g, (t.getMonth() + 101).toString().slice(1))
      .replace(/DD/gi, (t.getDate() + 100).toString().slice(1))
      .replace(/hh/g, (t.getHours() + 100).toString().slice(1))
      .replace(/mm/g, (t.getMinutes() + 100).toString().slice(1))
      .replace(/ss/g, (t.getSeconds() + 100).toString().slice(1))
  }